9. Nmap NSE Scripts

NMAP has tons of scripts to do things like DoSing targets or exploiting them.


There are four types of NSE scripts:

  1. Prerule scripts – scripts that run before any of Nmap’s scan operations, they are executed when Nmap hasn’t gathered any information about a target.
  2. Host scripts – scripts executed after Nmap has performed normal operations such as host discovery, port scanning, version detection, and OS detection against a target host.
  3. Service scripts – scripts run against specific services listening on a target host
  4. Postrule scripts – scripts run after Nmap has scanned all of its target hosts.

These scripts are futher grouped under following categories:

  1. Auth: Use to test whether you can bypass authentication mechanism

  2. Broadcast: Use to find other hosts on the network and automatically add them to scanning que.

  3. Brute: Use for brute password guessing.

  4. Discovery: Use to discover more about the network.

  5. Dos (Denial of Service): Use to test whether a target is vulnerable to DoS

  1. Exploit: Use to actively exploit a vulnerability

  2. Fuzzer: Use to test how server responds to unexpected or randomized fields in packets and determine other potential vulnerabilities

  3. Intrusive: Use to perform more intense scans that pose a much higher risk of being detected by admins.

  4. Malware: Use to test target for presence of malware

  5. Safe: Use to perform general network security scan that's less likely to alarm remote administrators

  6. Vuln: Use to find known vulnerabilities on the target

  7. default: These include scripts whic are fast and excludes brute force authentication crackers, web spiders, and any other scripts which can take minutes or hours to scan a single service and less privacy invasive (means do not use external services like whois lookup).
    These scripts are almost always in the safe category though there may be few intrusive scripts.
    Run them using -sC or -A or --script=default option.
    A few default scripts are:

  1. version: These scripts are an extension to the version detection feature and cannot be selected explicitly. They are selected to run only if version detection (-sV) was requested.They do not produce service or host script results.

  2. external: These scripts may send data to a third-party database or other network resource.Example: whois-ip, which makes a connection to whois servers to learn about the address of the target.Most scripts involve traffic strictly between the scanning computer and the client; any that do not are placed in this category.Third-party database will record anything you send to them, which in many cases will include your IP address and the address of the target.


--script-updatedb
This option updates the script database found in 'scripts/script.db' which is used by Nmap. It is only necessary to update the database if you have added or removed NSE scripts from the default scripts directory or if you have changed the categories of any script.

nmap --script-updatedb

Using * Wildcard

This is useful when you want to select scripts with a given name pattern.
Example: To run all scripts with name starting with ssh, run the command:

nmap --script "ssh-*" [TARGET]

Syntax

nmap --script [SCRIPPT CATEGORY or NAME] [TARGET] [OPTIONS]


Scripts in Action

Finding vulnerabilities on a target

nmap --script vuln [TARGET]

If vulnerability found nmap's output will list it's findings along with applicable CVEs and links to any exploits that exist in exploit-DB.

Actively Exploit Detected Vulnerabilities

nmap --script exploit [TARGET]

6905cc5c4d1649ea4246d17fb95482db.png

Brute Force Passwords

Nmap contains scripts for brute forcing dozens of protocols, including http-brute, oracle-brute, snmp-brute, etc. Use the following command to perform brute force attacks to guess authentication credentials of a remote server.

nmap --script brute [TARGET]

43d6a57e653593ddd54e74b915530137.png

1e1ee10b7e59da8f96069495ab6e3ae1.png

Check whether the target is vulnerable to DoS

nmap --script dos [TARGET]

This will tell you whether the target is vulnerable without actually launching a dos attack.


Get help regarding a script

sudo nmap --script-help [script name].nse

fddef36ee792174e3f9b8816c2d6ac1e.png

Search for scripts
Use Google
OR

--script help * (service or protocol name)*

f860355052d6fe0205b2ce3d7e84ac14.png


Using Boolean Expressions (or,and,not)
Select scripts using boolean expressions which can be build using the and, or, and not operators. And names in a Boolean expression may be a category, a filename from script.db, or all.

Load scripts from the default or broadcast categories

nmap --script "default or broadcast" [TARGET]

OR

nmap --script default,broadcast [TARGET]

Load all scripts omitting those in the vuln category

nmap --script "not vuln" [TARGET]

Load scripts in the default, or broadcast categories, leaving out those with names starting with ssh-

nmap --script "(default or broadcast) and not ssh-*" [TARGET]

Combine categories, script names, a directory containing custom scripts or a boolean expression to load scripts

nmap --script broadcast,vuln,ssh-auth-methods,/path/to/custom/scripts [TARGET]